package com.uto;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class GameChooser extends Activity implements OnClickListener {

	private User user;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.game_type);

		user = getIntent().getParcelableExtra("user");
		
		// Set up click listeners for all the buttons
		View continueButton = findViewById(R.id.new_game_button);
		continueButton.setOnClickListener(this);
		View newButton = findViewById(R.id.join_game_button);
		newButton.setOnClickListener(this);
		View clearButton = findViewById(R.id.clear_user_button);
		clearButton.setOnClickListener(this);
	}

	
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.new_game_button:
			intent = new Intent(this , NewGame.class);
			intent.putExtra("user", user);
			startActivity(intent);
			break;

		case R.id.join_game_button:
			intent = new Intent(this , JoinGame.class);
			intent.putExtra("user", user);
			startActivity(intent);
			break;
		
		case R.id.clear_user_button:
			SharedPreferences settings = getSharedPreferences(UTO.USER_FILE, 0);
			SharedPreferences.Editor editor = settings.edit();
			editor.putString("firstName", null);
			editor.putString("lastName", null);
			editor.putString("username", null);
			editor.putString("password", null);
		    // Commit the edits!
		    editor.commit();
		    finish();
			break;
		}

	}

}
